package com.magic.gre.ui.fragment;

import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;

import com.magic.gre.R;
import com.magic.gre.adapter.Guide3Adapter;
import com.magic.gre.base.fragment.BaseFragment;
import com.magic.gre.entity.Guide3Bean;
import com.magic.gre.entity.SerializableMap;
import com.noname.lib_base_java.entity.MsgEvent;
import com.noname.lib_base_java.net.RxBus;
import com.noname.lib_base_java.util.SelectHelper;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Author: Lmoumou
 * Date: 2019-01-11 17:34
 * 文件名: Guide3Fragment
 * 描述:
 */
public class Guide3Fragment extends BaseFragment implements Guide3Adapter.OnItemClickListener {

    @BindView(R.id.mRecyclerView)
    RecyclerView mRecyclerView;
    @BindView(R.id.bt1)
    Button bt1;

    public static Guide3Fragment newInstance(SerializableMap serializableMap) {
        Guide3Fragment fragment = new Guide3Fragment();
        Bundle bundle = new Bundle();
        bundle.putSerializable("parmsMap", serializableMap);
        fragment.setArguments(bundle);
        return fragment;
    }

    private SerializableMap serializableMap;

    private Guide3Adapter adapter;
    private List<Guide3Bean> dataList = new ArrayList<>();

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_guide_3;
    }

    @Override
    protected void initView(View view, Bundle savedInstanceState) {

        serializableMap = (SerializableMap) getArguments().getSerializable("parmsMap");

        bt1.setSelected(true);
        initData();
        adapter = new Guide3Adapter(mContext, dataList);
        adapter.setOnItemClickListener(this);
        mRecyclerView.setLayoutManager(new GridLayoutManager(mContext, 2));
        mRecyclerView.setAdapter(adapter);
    }

    @OnClick(value = {R.id.skip_bt, R.id.next_tv})
    protected void onClick(View view) {
        switch (view.getId()) {
            case R.id.skip_bt:
            case R.id.next_tv:
                send();
                break;
//            case R.id.next_tv:
//                Guide3Bean selectBean = SelectHelper.getSelectBean(dataList);
//                if (selectBean != null) {
//                    serializableMap.getMap().put("lastGrade", selectBean.getContent());
//                    send();
//                }
//                break;

        }
    }

    private void send() {
        MsgEvent msgEvent = new MsgEvent(MsgEvent.GUIDE_NEXT);
        msgEvent.put("next", 3);
        RxBus.getInstance().post(msgEvent);
    }


    private void initData() {
        dataList.clear();
        Guide3Bean bean = new Guide3Bean("315以下");

        dataList.add(bean);
        dataList.add(new Guide3Bean("315+"));
        dataList.add(new Guide3Bean("320+"));
        dataList.add(new Guide3Bean("325+"));
        dataList.add(new Guide3Bean("330+"));
    }

    @Override
    public void onItemClick() {
        Guide3Bean selectBean = SelectHelper.getSelectBean(dataList);
        if (selectBean != null) {
            serializableMap.getMap().put("lastGrade", selectBean.getContent());
            send();
        }
    }
}
